//
//  DDToolBar.swift
//  swift微博
//
//  Created by whitcast on 16/7/14.
//  Copyright © 2016年 whitcast. All rights reserved.
//

import UIKit
import SnapKit

class DDToolBar: UIToolbar {
    //模型vm
    var statuesViewModel:DDStatuesViewModel?{
        didSet{
        //转发数 (statuesViewModel?.statuesModel?.reposts_count)!
       let title1 = statuesViewModel?.judgeContentOfBtn("转发", count:(statuesViewModel?.statuesModel?.reposts_count)!)
        reposts_countBtn.setTitle(title1, forState: .Normal)
        //赞的数量
            let title2 = statuesViewModel?.judgeContentOfBtn("赞", count: (statuesViewModel?.statuesModel?.attitudes_count)!)
            attitudes_countBtn.setTitle(title2, forState: .Normal)
            //评论数量
            let title3 = statuesViewModel?.judgeContentOfBtn("评论", count: (statuesViewModel?.statuesModel?.comments_count)!)
            comments_countBtn.setTitle(title3, forState: .Normal)
        
        }
    }
    
    //转发
    lazy var reposts_countBtn: DDToolbarButton = {
    
        let btn = DDToolbarButton.setBtn("转发",imageName: "timeline_icon_retweet")
        
        return btn
    }()
    //评论
    lazy var comments_countBtn: DDToolbarButton = {
        let btn = DDToolbarButton.setBtn("评论",imageName: "timeline_icon_comment")
        
        return btn
    }()
    //赞
    lazy var attitudes_countBtn: DDToolbarButton = {
        let btn = DDToolbarButton.setBtn("赞",imageName: "timeline_icon_unlike")
        
        return btn
    }()
   
    override init(frame: CGRect) {
        super.init(frame:frame)
        
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //创建控件和约束
    func setUpUI() {
        //添加
        addSubview(reposts_countBtn)
        addSubview(comments_countBtn)
        addSubview(attitudes_countBtn)
        
        //约束
        reposts_countBtn.snp_makeConstraints { (make) -> Void in
            make.bottom .equalTo(self)
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.width.equalTo(comments_countBtn)
        }
        comments_countBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(reposts_countBtn.snp_trailing)
            make.trailing.equalTo(attitudes_countBtn.snp_leading)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
        }
        attitudes_countBtn.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(self)
            make.trailing.equalTo(self)
            make.top.equalTo(self)
            make.width.equalTo(reposts_countBtn)
        }
        self.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.trailing.equalTo(self)
            make.top.equalTo(self)
            make.height.equalTo(34)
        }
        
    }
  
}


